#
#/home/zhaigy/local/libevent/

#VPATH=src:libsphinxclient:json:log:libhttp:libthreadpool

EVENT_H=/home/zhaigy/local/libevent/include
EVENT_LIB=/home/zhaigy/local/libevent/lib

CC=gcc
CXX = g++

#C_FLAGS += -g -Wall -O0
C_FLAGS += -g -O0
LIB_FLAGS = -lpthread -levent -levent_pthreads
LIB = -L$(EVENT_LIB)
INC = -I$(EVENT_H)

SUBDIR =src log json libsphinxclient libthreadpool libhttp
#SUBDIRS=$(shell ls -d */ | grep -v 'bin' | grep -v 'lib' | grep -v 'include' | grep -v 'etc')

TOPSRC=$(wildcard *.c) $(wildcard *.cpp)
TOPOBJ=$(TOPSRC:%.c=%.o) $(TOPSRC:%.cpp=%.o)
SUBSRC_C=$(shell find $(SUBDIR) -name '*.c')
SUBSRC_CPP=$(shell find $(SUBDIR) -name '*.cpp')
SUBSRC=$(SUBSRC_C) $(SUBSRC_CPP)
SUBOBJ_C=$(SUBSRC_C:%.c=%.o)
SUBOBJ_CPP=$(SUBSRC_CPP:%.cpp=%.o)
SUBOBJ=$(SUBOBJ_C) $(SUBOBJ_CPP)

TARGET = sphinx_http_proxy_c

all: INFO $(TARGET)

INFO: 
	@echo "TOPSRC"
	@echo $(TOPSRC)
	@echo "TOPOBJ"
	@echo $(TOPOBJ)
	@echo "SUBSRC"
	@echo $(SUBSRC)
	@echo "SUBOBJ"
	@echo $(SUBOBJ)

$(TARGET):$(TOPOBJ) $(SUBOBJ)
	$(CXX) $(C_FLAGS) $(LIB_FLAGS) $(LIB) -o $@ $^
	ctags -R
.c.o:
	@echo $(@D)/$(<F) " -> " $(@D)/$(@F)
	$(CC) $(C_FLAGS) $(INC) -c $(@D)/$(<F) -o $(@D)/$(@F)

.cpp.o:
	@echo $(@D)/$(<F) " -> " $(@D)/$(@F)
	$(CXX) $(C_FLAGS) $(INC) -c $(@D)/$(<F) -o $(@D)/$(@F)

clean:
	rm -f $(TARGET) $(TOPOBJ) $(SUBOBJ)

